<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>部门员工信息录入</title>
    <script src="/js/jquery-3.4.1.min.js"></script>
</head>
<body>
<h3>部门员工信息添加</h3>
<form id="frmadd">
    姓 名:<input name="empName" type="text"/><br/>
    性 别:<input name="gender" type="radio" value="1"/>男 &nbsp;<input name="gender" type="radio" value="0"/>女<br/>
    生 日:<input name="birthday" type="date"/><br/>
    入职日期:<input name="hireDate" type="date"/><br/>
    工 资:<input name="salary" type="text"/><br/>
    地 址:<input name="address" type="text"/><br/>
    部 门:<select name="deptId" id="selDeptId">
    <option value="0">请选择</option>
</select><br/>
    <input name="btnadd" id="btnadd" type="button" value="保存" onclick="doAddEmp()"/>
    <input name="btnreset" type="reset" value="重置"/>
</form>
</body>
<script>
    $(document).ready(function(){
        loadDepts();
    });


    function doAddEmp() {
        $.ajax({
            url: "/admin/empl/doadd",
            type: "post",
            data: $("#frmadd").serialize(),
            dataType: "json",
            success: function (result) {
                if (result.errorCode == 200) {
                    window.location.href = "/pages/ajax.html";
                } else {
                    alert(result.errorMsg);
                }
            }
        });
    }
    function loadDepts() {
        $.ajax({
            url: "/admin/dept/list",
            type: "post",
            dataType: "json",
            success: function (result) {
                if (result.errorCode == 200) {
                    for (var i = 0; i < result.data.length; i++) {
                        var dept = result.data[i];
                        $("#selDeptId").append(`<option value="${dept.id}">${dept.deptName}</option>`);
                    }
                }
            }
        });
    }
 </script>
</html>